<?php //strip
/**
 * Implementation of the model for users.
 * 
 * @package odCatalogWpPlugin
 * @subpackage odCatalogWpPlugin_Models
 * @author Ondrej Donek <ondrejd@gmail.com>
 */
class odCatalogWpPlugin_Models_User extends odWpPlugin_Model_Simple
{
	public function __construct()
	{
		global $wpdb;
		
		$this->mTableName = $wpdb->prefix . 'catalog_users';
		$this->mPrimary = 'ID';
		$this->mCheckColumn = 'title';
		$this->mColumns = array(
			'ID' => array('type' => 'int', 'primary' => true),
			'language' => array('type' => 'char', 'length' => 75),
			'nationality' => array('type' => 'char', 'length' => 75),
			'title' => array('type' => 'char', 'length' => 75),
			'firstname' => array('type' => 'char', 'length' => 75),
			'middlename' => array('type' => 'char', 'length' => 75),
			'surname' => array('type' => 'char', 'length' => 75),
			'address_ID' => array('type' => 'bigint', 'length' => 20),
      'birthday' => array('type' => 'date'),
			// TODO Type `enum`!!!!
			'sex' => array('type' => 'tinyint', 'length' => 1, 'comment' => 'NULL and 0 are mens, 1 are womens.'),
			'children' => array('type' => 'int', 'length' => 1),
			'interests' => array('type' => 'tinytext'),
			'agreement' => array('type' => 'int', 'length' => 1),
			'card' => array('type' => 'char', 'length' => 25, 'notnull' => true, 'default' => 'classic'),
			'from' => array('type' => 'char', 'length' => 255),
			'deleted' => array('type' => 'tinyint', 'length' => 1)
		);
	}
		
	public function get($aFilter = '', $aCount = 0, $aLimitFrom = 0)
	{
		global $wpdb;
		
		$query = 'SELECT ' . PHP_EOL . 
				'  `t1`.* ' . PHP_EOL . 
				'FROM `' . $this->mTableName . '` AS `t1` ' . PHP_EOL . 
				'WHERE ' . PHP_EOL . $aFilter . PHP_EOL;
		
		if($aLimitFrom > 0 && $aCount > 0) {
			$query .= 'LIMIT ' . $aLimitFrom . ', ' . $aCount . ' ;';
		}
		else if($aCount > 0) {
			$query .= 'LIMIT ' . $aCount . ' ;';
		}
		
		return $wpdb->get_results($query, ARRAY_A);
	}
	
} // End of odCatalogWpPlugin_Models_User
